<template>
  <view class="demo-container">
    <!-- 基础用法 -->
    <view class="demo-block">
      <view class="demo-block__title">基础用法</view>
      <view class="demo-block__content">
        <fu-search
          v-model="value1"
          placeholder="请输入搜索关键词"
          @search="onSearch"
        />
      </view>
    </view>
    
    <!-- 事件监听 -->
    <view class="demo-block">
      <view class="demo-block__title">事件监听</view>
      <view class="demo-block__content">
        <fu-search
          v-model="value2"
          placeholder="请输入搜索关键词"
          @search="onSearch"
          @clear="onClear"
          @cancel="onCancel"
        />
      </view>
    </view>
    
    <!-- 自定义样式 -->
    <view class="demo-block">
      <view class="demo-block__title">自定义样式</view>
      <view class="demo-block__content">
        <fu-search
          v-model="value3"
          placeholder="请输入搜索关键词"
          background="#ffffff"
          :round="false"
        >
          <template #action>
            <text class="custom-action">搜索</text>
          </template>
        </fu-search>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  data() {
    return {
      value1: '',
      value2: '',
      value3: ''
    }
  },
  methods: {
    onSearch(value) {
      uni.showToast({
        title: `搜索：${value}`,
        icon: 'none'
      })
    },
    onClear() {
      uni.showToast({
        title: '清空搜索',
        icon: 'none'
      })
    },
    onCancel() {
      uni.showToast({
        title: '取消搜索',
        icon: 'none'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.demo-container {
  padding: 20rpx;
}

.demo-block {
  margin-bottom: 30rpx;
  
  &__title {
    margin-bottom: 20rpx;
    font-size: var(--fu-font-size-lg);
    color: var(--fu-text-color);
  }
  
  &__content {
    background-color: #fff;
    border-radius: var(--fu-radius-base);
    overflow: hidden;
  }
}

.custom-action {
  color: var(--fu-primary-color);
}
</style> 